package club.ruanx.auth.filter;

import club.ruanx.auth.provider.UserProvider;
import club.ruanx.auth.token.UserToken;
import club.ruanx.security.provider.AbstractAuthenticationLoginFilterProvider;
import club.ruanx.security.provider.BaseDetailsAuthenticationProvider;
import club.ruanx.security.token.AuthenticationTokenGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

/**
 * @author 阮胜
 * @date 2018/9/14 18:50
 */

@Component
public class UserAuthenticationLoginFilter extends AbstractAuthenticationLoginFilterProvider {
    private UserProvider userProvider;

    @Autowired
    @Qualifier("userDetailService")
    private UserDetailsService userDetailsService;


    @Override
    public String obtainLoginUrl() {
        return "/user/login";
    }

    @Override
    public UserDetailsService obtainUserDetailsService() {
        return userDetailsService;
    }

    @Override
    public BaseDetailsAuthenticationProvider obtainDetailsAuthenticationProvider() {
        if (userProvider == null) {
            userProvider = new UserProvider();
        }
        return userProvider;
    }

    @Override
    public AuthenticationTokenGenerator tokenGenerator() {
        return UserToken::new;
    }


}
